<template>
  <div class="setPasswor">
    <div class="set-layer">
      <div class="set-title">
        <span>设置密码</span>
        <hr />
      </div>
      <el-form
        ref="setpasswor"
        :model="setpasswor"
        class="demo-form-inline"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="密码：" prop="passone">
          <el-input
            v-model="setpasswor.passone"
            placeholder="6-16位，必须包含数字和字母"
            type="password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item label="确认密码：" prop="passtwo">
          <el-input
            v-model="setpasswor.passtwo"
            placeholder="再次填写上面的密码"
            type="password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('setpasswor')">确定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>

export default {
  data() {
    var isequality = (rule, value, callback) => {
      if (value === this.setpasswor.passone) {
        return callback();
      }
      callback(new Error("两次密码不一致"));
    };
      var  isequality1=(rule, value, callback)=>{
          if (/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[~!\`\<\>\|\_\-\(\)/\@\\#\^\&$%\*-\+=:,\\?\[\]\{}]).{8,18}$/.test(value)) {
              return callback();
          }
          callback(new Error("密码为8-18位，且必须包含数字大小写字母特殊字符"));
      }
    return {
      setpasswor: {
        passone: "",
        passtwo: "",
      },
      rules: {
        passone: [
          {
            required: true,
            message: "为了您的安全，请设置你的密码",
            trigger: "blur",
          },
//            {
//                min: 8,
//                max: 18,
//                message: "密码长度位8-18位",
//                trigger: "blur",
//            },
            { validator: isequality1, trigger: "blur" },
        ],
        passtwo: [
          { required: true, message: "请再次输入你的密码", trigger: "blur" },
            {
                min: 8,
                max: 18,
                message: "密码长度位8-18位",
                trigger: "blur",
            },
          { validator: isequality, trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$http
            .put("/trademark/proPublic/set", {
              password: this.setpasswor.passtwo,
              phoneNum: this.$store.state.phoneNumber,

            })
            .then(
              ({ data: res }) => {
                if (res.code !== 200)
                  return ;
                this.$message.success("密码设置成功");
                this.$store.commit("setFlat", 1);
                this.$router.push("/business/allBusiness/register");
              },
//              (err) => this.$message.error("网络错误")
            );
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.setPasswor {
  padding: 42px;
  .set-layer {
    .set-title {
      width: 900px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 35px;
      span {
        font-size: 18px;
        color: #666666;
        padding: 0 25px;
        font-weight: 600;
      }
      hr {
        width: 744px;
        height: 0;
        border: 1px solid #d9d9d9;
      }
    }
    .demo-form-inline {
      width: 350px;
    }
  }
}
</style>